import config
import View
import os

class CRlease:
    def __init__(self, home=None):

        #first get the configuration from the config file
        self.cfg = config.CConfig()
        if home == None:
            self.cfg.UpdateFromFile("config.xml")
        else:
            self.cfg.UpdateFromFile(os.path.join(home,"config.xml"))

        #get the view
        self.view = View.CDcmView(self.cfg.viewHome)
        self.view.SetConfig(self.cfg)

    def UpdateView(self):
        sele = self.cfg.selection
        if sele.UpdateView == "Y" or sele.All == "Y":
            print "----------->>>>>>>>>>>        Update View        <<<<<<<<<<<-----------"
            self.view.UpdateAll()

    def UpdateVersionFile(self):
        sele = self.cfg.selection
        if sele.UpdateVF == "Y" or sele.All == "Y":
            print "----------->>>>>>>>>>>    Update Version File    <<<<<<<<<<<-----------"
            self.view.UpdateVersionFile()

    def GenerateCode(self):
        sele = self.cfg.selection
        if sele.Generate == "Y" or sele.All == "Y":
            print "----------->>>>>>>>>>>       Generate Code       <<<<<<<<<<<-----------"
            self.view.GenerateCode()

    def CompileCode(self):
        sele = self.cfg.selection
        if sele.Compile == "Y" or sele.All == "Y":
            print "----------->>>>>>>>>>>        Compile Code       <<<<<<<<<<<-----------"
            self.view.Compile()

    def SaveImage(self):
        sele = self.cfg.selection
        if sele.Save == "Y" or sele.All == "Y":
            print "----------->>>>>>>>>>>        Save Image         <<<<<<<<<<<-----------"
            self.view.SaveImage()

    def run(self):
        print "----------->>>>>>>>>>>        Run Release        <<<<<<<<<<<-----------"

        self.UpdateView()

        self.UpdateVersionFile()

        self.GenerateCode()

        self.CompileCode()

        self.SaveImage()

        print "----------->>>>>>>>>>>        End Release        <<<<<<<<<<<-----------"


if __name__ == "__main__":
    release = CRlease()
    release.run()
